package Model.alignments;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import Control.Zoomable;
import Model.ValidPosition;

public class IntronCollapsedAlignment extends CollapsedAlignment implements
		Subset0Alignment {

	public IntronCollapsedAlignment(Subset0Alignment alignment) {
		super(alignment);
	}

	@Override
	public void updateReferencePosition() {
		if (getAligmentCount() == 0)
			return;

		referencePosition = containedAlignments.get(0).getValidPositions()
				.get(0).start;
	}

	@Override
	boolean isCandidateAddition(Subset0Alignment temp) {
		if (temp instanceof IntronCollapsedAlignment) {
			return (Math.abs(this.referencePosition
					- ((IntronCollapsedAlignment) temp).referencePosition) <= COLLAPSE_WIGGLE);
		}
		return false;
	}

	@Override
	public void draw(Graphics graphic, int x, int y) {
		Color color = new Color(255, 255, 255);
		Graphics2D g2d = (Graphics2D) graphic;
		Zoomable z = Zoomable.getInstance();

		ValidPosition vp = this.getMaxBound();

		g2d.setColor(color);
		vp.x = x + z.calcDist(vp.start);
		vp.y = y - 1;
		vp.width = z.calcDist(vp.getDistance());
		vp.height = 6;
		g2d.fill(vp);

		g2d.setColor(new Color(0, 0, 0));
		g2d.draw(vp);
	}

	@Override
	public String toString() {
		return "Intron Collapsed Alignment";
	}
}
